package com.xch.sort;

import cn.hutool.core.comparator.CompareUtil;
import cn.hutool.core.util.ArrayUtil;

import static cn.hutool.core.util.ArrayUtil.swap;

public class InsertionSort {

    public static <E extends Comparable> void sort(E[] arr){


        if(ArrayUtil.isEmpty(arr)) return;

        for(int i=0;i<arr.length;i++){

            E e = arr[i];

            for(int j = i-1;j>=0;j--){

                if(CompareUtil.compare(arr[j],e)>0) arr[j+1] =arr[j];
                else {
                    arr[j] = e;
                    break;
                }
            }


        }
    }

    public static void main(String[] args) {
        int [] dataSize ={10000,100000};
        for(int i=0;i<dataSize.length;i++){
            Integer[] array = ArrayGenerate.generateRandomArray(dataSize[i], dataSize[i]);
            SortingHelper.sort("InsertionSort",array);
        }
    }

}
